package cn.bincker.mybatis.encrypt.data.migration;

import cn.bincker.mybatis.encrypt.core.EncryptExecutor;
import cn.bincker.mybatis.encrypt.data.migration.entity.ColumnInfo;
import cn.bincker.mybatis.encrypt.data.migration.entity.MigrateTable;
import cn.bincker.mybatis.encrypt.data.migration.impl.EncryptTask;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.function.Consumer;

@SuppressWarnings("unused")
public interface MigrateDatabase {
    DataSource getSrcDataSource();
    void setSrcDataSource(DataSource dataSource);
    DataSource getDistDataSource();
    void setDistDataSource(DataSource dataSource);
    void setProgressListener(ProgressListener listener);
    ExecutorService getExecutorService();
    void setExecutorService(ExecutorService executorService);
    void registerTable(Class<?> entityClass);
    void registerTable(MigrateTable table);
    Collection<MigrateTable> getMigrateTables();
    EncryptExecutor getEncryptExecutor();
    void setEncryptExecutor(EncryptExecutor encryptExecutor);
    List<ColumnInfo> getSrcColumns(Connection connection, MigrateTable table);
    List<ColumnInfo> getDistColumns(Connection connection, MigrateTable table);
    void setOnEncryptThreadInitListener(Consumer<EncryptTask> listener);
    void setOnEncryptThreadDestroyListener(Consumer<EncryptTask> listener);
    void setEncryptQueueLimit(int limit);
    void setInsertQueueLimit(int limit);
    void setSelectThreads(int threads);
    void setEncryptThreads(int threads);
    void setInsertThreads(int threads);
    void migrate() throws SQLException;
    @FunctionalInterface
    interface ProgressListener {
        void onProgress(int currentTables, int totalTables, MigrateTable table, String msg);
    }
}
